﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace CellarDoor.Gui
{
    public class UiIcon : UiButton
    {
        public enum Style
        {
            Stretch,
            PreserveRatio,
        }

        public UiIcon()
            : base()
        {
        }

        private Texture2D iconTexture;
        public Texture2D IconTexture
        {
            get { return skinTexture; }
            set { iconTexture = value; }
        }

        private UiIcon.Style iconStyle;
        public UiIcon.Style IconStyle
        {
            get { return iconStyle; }
            set { iconStyle = value; }
        }

        public override void Draw(SpriteBatch spriteBatch)
        {
            base.Draw(spriteBatch);

            if (iconTexture != null)
            {
                switch (iconStyle)
                {
                    case Style.Stretch:
                        spriteBatch.Draw(iconTexture, base.SkinDestination.GetArea(), base.TintColor);
                        break;
                    case Style.PreserveRatio:
                        Vector2 scale = new Vector2(BoundsScaled.Width / (float)skinTexture.Width, BoundsScaled.Height / (float)skinTexture.Height);
                        spriteBatch.Draw(iconTexture, new Rectangle((int)BoundsScaled.X, (int)BoundsScaled.Y, (int)(skinTexture.Width * scale.X), (int)(skinTexture.Height * scale.Y)), TintColor);
                        break;
                    default:
                        break;
                }
            }
        }
    }
}
